#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int len = n - k;
    int left = 1e9, right = 0;
    for (int i = 0; i <= n - len; ++i) {
        int midLeft, midRight;
        if (len % 2 == 1) {
            midLeft = midRight = a[i + len / 2];
        } else {
            midLeft = a[i + len / 2 - 1];
            midRight = a[i + len / 2];
        }
        left = min(left, midLeft);
        right = max(right, midRight);
    }

    cout << right - left + 1 << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}